package com.gosophia.oa.test.functional;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.gosophia.oa.test.CustomSeleneseTestCase;




public class FTDataDictionary extends CustomSeleneseTestCase {

	@Before
	public void setUp() throws Exception {
		super.setUp("http://localhost:8080/");
	}

	@After
	public void tearDown() throws Exception {
		if (selenium != null)
			selenium.close();
		super.tearDown();
	}
	
	public void testListPage() throws Exception {
		// 登录
		selenium.open("/OA/");
		selenium.type("j_username", "admin");
		selenium.type("j_password", "admin");
		selenium.click("loginBtn");
		selenium.waitForPageToLoad("10000");

		// 进入列表页面
		selenium.click("link=数据字典");
		selenium.waitForPageToLoad("10000");
		assertPageTitle("北京市电子行政监察平台-数据字典", onPage("数据字典列表页面"));
		// 等待列表刷新完成
		waitForAppearanceOfElement("//div[@id='dataTable']/table", 10000);

		// 验证页面元素
		String[] listPageElementTexts = {
				"词条名",
				"词条类型",
				"描述",
				"操作",
				"首页","尾页"
				};
		verifyPresenceOfTexts(listPageElementTexts, onPage("数据字典列表页面"));
	}
	
	@Test
	public void testEditCustomEntryPage() throws Exception {
		// 登录
		selenium.open("/OA/");
		selenium.type("j_username", "admin");
		selenium.type("j_password", "admin");
		selenium.click("loginBtn");
		selenium.waitForPageToLoad("10000");

		// 进入列表页面
		selenium.click("link=数据字典");
		selenium.waitForPageToLoad("10000");
		assertPageTitle("北京市电子行政监察平台-数据字典", onPage("数据字典列表页面"));
		// 等待列表刷新完成
		waitForAppearanceOfElement("//div[@id='dataTable']/table", 10000);

		//编辑可定制词条
		selenium.type("searchCond", "关联业务");
		selenium.click("searchButton");
		//等待搜索结果
		waitForDisappearanceOfText("内置", 10000);
		waitForAppearanceOfText("关联业务", 10000);
		selenium.click("link=编辑");
		selenium.waitForPageToLoad("10000");
		assertPageTitle("北京市电子行政监察平台-编辑字典词条", onPage("编辑可定制词条页面"));

		// 验证页面元素
		String[] editPageElementTexts = {
				"编辑词条",
				"词 条 名",
				"词条类型","可定制",
				"描述",
				"数据项",
				"日常业务","行政投诉"
				};
		verifyPresenceOfTexts(editPageElementTexts, onPage("编辑可定制词条页面"));
		
		//新增数据项
		selenium.click("add");
		waitForAppearanceOfElement("//div[@id='contentArea']//h1[text()='新增数据项']", 10000);		
		String[] addValuePageElementTexts = {
				"数据项名称","最长16个字符",
				"Key值","最长32个字符",
				"状态","启用","禁用",
				"描述"
				};
		verifyPresenceOfTexts(addValuePageElementTexts, onPage("新增数据项子页面"));
				
		//数据项详细
		selenium.click("//span[@name='行政投诉']");
//		selenium.fireEvent("1002_0_行政投诉", "click");
		waitForAppearanceOfElement("//div[@id='contentArea']//h1[text()='数据项详细信息']", 10000);		
//		waitUntilAppearanceOfText("数据项详细信息", 30);		
		String[] valueDetailsElementTexts = {
				"数据值名称",
				"数据值Key值",
				"状态",
				"描述"
				};
		verifyPresenceOfTexts(valueDetailsElementTexts, onPage("数据项详细子页面"));
		
		//编辑数据项
		selenium.click("edit");
		waitForAppearanceOfElement("//div[@id='contentArea']//h1[text()='编辑数据项']", 10000);		
//		waitUntilAppearanceOfText("编辑数据项", 10);		
		String[] editValueElementTexts = {
				"数据项名称","最长16个字符",
				"Key值","最长32个字符",
				"状态","启用","禁用",
				"描述"
				};
		verifyPresenceOfTexts(editValueElementTexts, onPage("编辑数据项子页面"));
	}
	
	@Test
	public void testEditBuiltinEntryPage() throws Exception {
		// 登录
		selenium.open("/OA/");
		selenium.type("j_username", "admin");
		selenium.type("j_password", "admin");
		selenium.click("loginBtn");
		selenium.waitForPageToLoad("10000");

		// 进入列表页面
		selenium.click("link=数据字典");
		selenium.waitForPageToLoad("10000");
		assertPageTitle("北京市电子行政监察平台-数据字典", onPage("数据字典列表页面"));
		// 等待列表刷新完成
		waitForAppearanceOfElement("//div[@id='dataTable']/table", 10000);

		//编辑可定制词条
		selenium.type("searchCond", "民族");
		selenium.click("searchButton");
		//等待搜索结果
		waitForDisappearanceOfText("可定制", 10000);
		waitForAppearanceOfText("民族", 10000);
		selenium.click("link=编辑");
		selenium.waitForPageToLoad("10000");
		assertPageTitle("北京市电子行政监察平台-编辑字典词条", onPage("编辑内置词条页面"));
		
		// 验证页面元素
		String[] editPageElementTexts = {
				"编辑词条",
				"词条名",
				"词条类型","内置",
				"描述",
				"数据项",
				"瑶族"
				};
		verifyPresenceOfTexts(editPageElementTexts, onPage("编辑内置词条页面"));
				
		//数据项详细
		selenium.click("//span[@name='瑶族']");
		waitForAppearanceOfElement("//div[@id='contentArea']//h1[text()='数据项详细信息']", 10000);		
		String[] valueDetailsElementTexts = {
				"数据值名称",
				"数据值Key值",
				"状态",
				"描述"
				};
		verifyPresenceOfTexts(valueDetailsElementTexts, onPage("数据项详细子页面"));
		
		//编辑数据项
		selenium.click("edit");
		waitForAppearanceOfElement("//div[@id='contentArea']//h1[text()='编辑数据项']", 10000);		
		String[] editValueElementTexts = {
				"数据项名称","最长16个字符",
				"Key值","最长32个字符",
				"状态","启用","禁用",
				"描述"
				};
		verifyPresenceOfTexts(editValueElementTexts, onPage("编辑数据项子页面"));
	}

}
